/*
package com.itheima.filter;


import com.itheima.utils.JwtUtils;
import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpStatus;
import org.springframework.util.StringUtils;

import java.io.IOException;



@Slf4j
@WebFilter(urlPatterns = "/*")
public class TokenFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        Filter.super.init(filterConfig);
    }

    @Override
    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
        System.out.println("拦截到了请求...");
        HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse response = (HttpServletResponse) res;
        //1.获取请求路径
        String url = request.getRequestURI().toString();
        //2.判断请求路径是否包含：login，若包含，则放行
        if (url.contains("login")) {
            log.info("登录请求，放行");
            chain.doFilter(request, response);
            return;
        }
        //3.获取请求头中的token
        String token = request.getHeader("token");

        //4.判断token是否为空，若为空，响应401
      */
/*  !StringUtils.hasLength(token)*//*

        if (token == null || token.isEmpty()) {
            log.info("请求头中无token信息，返回401");
            response.setStatus(401);
            return;
        }
        //5.解析token，判断是否解析成功，解析失败则返回401
        try {
            JwtUtils.parseJWT(token);
        } catch (Exception e) {
            e.printStackTrace();
            log.info("解析token失败，返回401");
            response.setStatus(HttpStatus.SC_UNAUTHORIZED);
            return;
        }
        //6.token不为空且解析成功，则放行
        log.info("token不为空且合法，放行");
        chain.doFilter(request, response);
    }
    @Override
    public void destroy() {
        Filter.super.destroy();
    }
}
*/
